<template>
  <el-header class="header">
    <el-menu mode="horizontal" :default-active="activeIndex" router>
      <el-menu-item index="/">首页</el-menu-item>
      <el-menu-item index="/about">关于</el-menu-item>
      <el-menu-item index="/ai">ai</el-menu-item>
      <!-- <el-menu-item><a href="http://134.175.177.137/capsule" style="position: absolute;width: 100%;">小程序</a></el-menu-item> -->
      <!-- <el-menu-item style="margin-left: 40px;"><a href="https://www.xit-edu.cn/2502-bole-h5/#/" style="position: absolute;width: 100%;">uniapp程序</a></el-menu-item> -->
      <div class="flex-grow" />
      <el-input
        v-model="searchText"
        placeholder="搜索文章"
        class="search-input"
        @keyup.enter="handleSearch"
      >
        <template #append>
          <el-button :icon="Search" @click="handleSearch"/>
        </template>
      </el-input>
    </el-menu>
  </el-header>
</template>

<script setup>
import { ref } from "vue";
// import { Search } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";

const activeIndex = ref("/");
const searchText = ref("");
const router = useRouter();


// 修改Header.vue中的handleSearch方法
const handleSearch = () => {
  if (searchText.value.trim()) {
    router.push({
      path: "/search",
      query: { q: searchText.value.trim() },
    });
  }
};
</script>

<style lang="scss" scoped>
.header {
  padding: 0;
  border-bottom: 1px solid #e6e6e6;

  .flex-grow {
    flex-grow: 1;
  }

  .search-input {
    width: 300px;
    margin: 12px 20px;
  }
}
</style>
